home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.ButtonModel;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
- import com.sun.java.swing.plaf.basic.BasicToggleButtonUI;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.Rectangle;
-
- public class MetalToggleButtonUI extends BasicToggleButtonUI {
- private static Color selectedColor;
- private static Color disabledTextColor;
- private static Color focusColor;
- protected static final Insets defaultMargin = new Insets(2, 14, 2, 14);
- private static final MetalToggleButtonUI metalToggleButtonUI = new MetalToggleButtonUI();
-
- public static ComponentUI createUI(JComponent b) {
- return metalToggleButtonUI;
- }
-
- public Insets getDefaultMargin(AbstractButton b) {
- return defaultMargin;
- }
-
- public void installUI(JComponent c) {
- super.installUI(c);
- selectedColor = UIManager.getColor("ToggleButton.selected");
- disabledTextColor = UIManager.getColor("ToggleButton.disabledText");
- focusColor = UIManager.getColor("ToggleButton.focus");
- }
-
- protected void paintButtonPressed(Graphics g, AbstractButton b) {
- Dimension size = ((Component)b).getSize();
- g.setColor(selectedColor);
- g.fillRect(0, 0, size.width, size.height);
- }
-
- protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
- Rectangle focusRect = new Rectangle();
- String text = b.getText();
- boolean isIcon = b.getIcon() != null;
- if (text != null & !text.equals("")) {
- if (!isIcon) {
- focusRect.setBounds(textRect);
- } else {
- focusRect.setBounds(iconRect.union(textRect));
- }
- } else if (isIcon) {
- focusRect.setBounds(iconRect);
- }
-
- g.setColor(focusColor);
- g.drawRect(focusRect.x - 1, focusRect.y - 1, focusRect.width + 1, focusRect.height + 1);
- }
-
- protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
- AbstractButton b = (AbstractButton)c;
- ButtonModel model = b.getModel();
- FontMetrics fm = g.getFontMetrics();
- if (model.isEnabled()) {
- g.setColor(((Component)b).getForeground());
- BasicGraphicsUtils.drawString(g, text, model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());
- } else {
- if (model.isSelected()) {
- g.setColor(UIManager.getColor("Button.background"));
- } else {
- g.setColor(UIManager.getColor("Button.disabledText"));
- }
-
- BasicGraphicsUtils.drawString(g, text, model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());
- }
-
- }
- }
-